<?php
/**
 * index.php
 * parse railbrowser.tpl
 *
 * PHP versions 5
 *
 * Copyright (C)
 * This program is free software. You can redistribute it and/or modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation. Either version 2 of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY. Without even the implied warranty
 * of ERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along with this program. Ff not, write to the Free Software
 * Fundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
 *
 * Copyright (C) 2006-2007
 *
 * @author Bastian Schröder <bs@chemanet.de>
 * @version 2008-04-17
 * @package railbrowser
 */

session_start();

// set default exception handler
function exception_handler( $exception ) {
	print_r( '<!--' . $exception . '-->' );
	die( 'Uncaught exception: ' . $exception->getMessage() );
}
set_exception_handler('exception_handler');

// includes
require_once( 'configs/railbrowser.conf.php' );
require_once( "$cfg_pahToPHPrail/rail_connector.class.php" );
require_once( "$cfg_resources_dir/smarty-2.6.18/Smarty.class.php" );

// include Smarty libary
$smarty = new Smarty();
$smarty->caching = false;
$smarty->template_dir = './templates/';
$smarty->compile_dir = $cfg_cache_dir;
$smarty->config_dir = $cfg_cache_dir;
$smarty->cache_dir = $cfg_cache_dir;
$smarty->left_delimiter = '{{';
$smarty->right_delimiter = '}}';

// define version and get svn revision
define('RAILBROWSER_VERSION', '1.0');
define('RAILBROWSER_REVISION', 'beta');

// connect
$rail = new rail_connector(
	$cfg_mysqlDb,
	$cfg_mysqlUser,
	$cfg_mysqlPasswd,
	$cfg_mysqlHost
);
$rail->login( $cfg_railUser, $cfg_railPasswd );

// set object
if( isset($_REQUEST['object']) && rail_factory::is_object($rail, $_REQUEST['object']) ){
	$_SESSION['object'] = $_REQUEST['object'];
	$object = rail_factory::get_object( $rail, $_REQUEST['object'] );
}
else if( isset($_SESSION['object']) ){
	if( rail_factory::is_object($rail, $_SESSION['object']) )
		$object = rail_factory::get_object( $rail, $_SESSION['object'] );
	else{
		unset( $_SESSION['object'] );
		$object = $rail->get_root();
	}
}
else $object = $rail->get_root();


/* ------------------------------------- display -------------------------------------- */
$smarty->assign( array(
	'href_onclick' => $cfg_exit_onclick,
	'resources_dir' => $cfg_resources_dir,
	'version' => RAILBROWSER_VERSION.'-'.RAILBROWSER_REVISION,
	'object' => $object->get_id(),
	'users_home' => $rail->get_user()->get_path()
));

// display
$smarty->display( 'railbrowser.tpl' );

?>